﻿using FinalYear.Helpers;
using System;

namespace FinalYear.iNavigate.Classes
{
    public class FeedbackSensor : Sensor
    {
        public FeedbackSensor(SerialManager manager)
            : base(manager)
        {
        }

        public void SendCollisionWarning(SCREENREGION regionToMove)
        {
            //try
            //{
            if (this.CheckDiagnostic())
            {
                if (regionToMove == SCREENREGION.LEFT)
                {
                    this.manager.currentPort.Write("1");
                }
                else if (regionToMove == SCREENREGION.RIGHT)
                {
                    this.manager.currentPort.Write("2");
                }
            }

            //}
            //catch (Exception ex)
            //{
            //    throw;
            //}
        }

        internal override bool CheckDiagnostic()
        {
            try
            {
                return this.manager.currentPort.IsOpen;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}